
import { _decorator, AnimationClip, Animation, Component, Node, SpriteFrame } from 'cc';
import { secondGun_specialSkill_config } from '../../manager/AppControll';
import { Loader } from '../../tools/LoadManger';
import { DamageStruct } from '../FightControl';
import { resManger } from '../../tools/ResManger';
const { ccclass, property } = _decorator;

@ccclass('SkillOrigin')
export class SkillOrigin extends Component {
    protected mSikllConfig: secondGun_specialSkill_config = null;
    protected mAnclp: AnimationClip = null;
    protected mStrPath: string = "image/bullet/"
    protected mAnSpf: SpriteFrame[] = [];
    protected mSpeed: number = 0;
    protected mDmg: DamageStruct = null;
    InitSkill(config: secondGun_specialSkill_config, dmg: DamageStruct) {
        this.mSikllConfig = config;
        this.mSpeed = this.mSikllConfig.skillSpeed;
        this.mDmg = dmg;
    }

    InitAnimation(callback?: () => void) {
        if (!this.mSikllConfig) return;
        resManger.GetSkillAniSpf(this.mSikllConfig.skillAni, (arr) => {
            if (!this.mSikllConfig) {
                if (!this.node) return;
                this.node.destroy();
                return;
            }
            let an: Animation = this.node.getComponent(Animation);
            if (!an) an = this.node.addComponent(Animation);
            this.mAnSpf = arr;
            const clip = AnimationClip.createWithSpriteFrames(this.mAnSpf, this.mAnSpf.length);
            clip.name = this.mSikllConfig.skillAni;
            clip.wrapMode = AnimationClip.WrapMode.Normal;
            clip.speed = this.mSikllConfig.skillAniSpeed;
            an.addClip(clip);
            if (callback) callback();
        })
    }
}


